package io.gitee.thinkbungee.utils;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;

/**
 * @author chenyichang
 * @date 2022/2/18
 */
public class SatelliteUtils {
    /**
     * 驼峰命名转下划线
     * 如：
     * username ==> username
     * updateTime ==> update_time
     *
     * @param camelCaseStr 驼峰命名字段
     * @return
     */
    public static String camelCaseToUnderline(String camelCaseStr) {
        return StringUtils.camelToUnderline(camelCaseStr);
    }

    /**
     * 转义特殊字符
     *
     * @param keyword
     * @return
     */
    public static String repalceSpecialWord(String keyword) {
        if (StrUtil.isNotEmpty(keyword)) {
            String[] fbsArr = {
                    "\\", "*", "+", "|",
                    "{", "}", "(", ")",
                    "^", "$", "[", "]",
                    "?", ",", ".", "&"
            };
            for (String key : fbsArr) {
                if (keyword.contains(key)) {
                    keyword = keyword.replace(key, "\\" + key);
                }
            }
        }
        return keyword;
    }
}
